# functions = [
#     {
#         "name": "joke",
#         "description": "讲笑话",
#         "parameters": {
#             "type": 'object',
#             "properties": {
#                 "setup": {
#                     "type": "string",
#                     "description": "笑话的开头",
#                 },
#                 "punchline": {
#                     "type": "string",
#                     "description": "笑话的结尾",
#                 }
#             },
#             "required": ["setup", "punchline"]
#         }
#     }
# ]
from _operator import itemgetter

from langchain_community.llms.tongyi import Tongyi
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate

llm = Tongyi()
prompt1 = ChatPromptTemplate.from_template("{person}来自哪个城市？只要城市")

prompt2 = ChatPromptTemplate.from_template("{city}属于哪个省份？用{language}语言回答")
chain1 = prompt1 | llm | StrOutputParser()
chain2 = (
        {"city": chain1, "language": itemgetter('language')} |
        prompt2 | llm | StrOutputParser()
)
# res = chain1.invoke({"person":"马化腾"})
# print(res)
res = chain2.invoke({"person": "马化腾", "language": "中文"})
print(res)
